// DeviceManager.h
#pragma once
#include <memory>
#include <unordered_map>
#include "Device.h"
#include "ThreadPool.h"
class DeviceManager {
public:
    DeviceManager(ThreadPool& pool) : threadPool(pool) {}
    
    void addDevice(const std::string& type, const std::string& config) {
        auto device = DeviceFactory::createDevice(type, config);
        std::lock_guard<std::mutex> lock(devicesMutex);
        devices[device->getId()] = device;
        updateDeviceInDB(*device);
    }
    void controlDevice(int id, const std::string& command) {
        threadPool.enqueue([this, id, command] {
            auto device = getDevice(id);
            device->executeCommand(command);
            updateDeviceInDB(*device);
            Logger::logDeviceAction(id, command);
        });
    }
private:
    std::mutex devicesMutex;
    std::unordered_map<int, std::shared_ptr<Device>> devices;
    ThreadPool& threadPool;
    
    void updateDeviceInDB(const Device& device) {
        // 数据库更新逻辑
    }
};